"""
Slide Content Data Model
Defines the structure for individual slide content and related data.
"""

from pydantic import BaseModel, Field, validator
from typing import List, Optional
from enum import Enum


class SlideType(str, Enum):
    """Available slide types"""
    TITLE = "title"
    CONTENT = "content"
    IMAGE = "image"
    CHART = "chart"
    CONCLUSION = "conclusion"
    SECTION_HEADER = "section_header"
    BULLET_POINTS = "bullet_points"
    COMPARISON = "comparison"


class SlideContent(BaseModel):
    """
    Data model for individual slide content
    
    Attributes:
        title: Slide title
        content: List of content items (bullet points, paragraphs, etc.)
        slide_type: Type of slide layout
        visual_elements: Suggested visual elements or placeholders
        notes: Speaker notes for the slide
        slide_number: Position in the presentation
    """
    
    title: str = Field(
        ...,
        min_length=1,
        max_length=200,
        description="Title of the slide"
    )
    
    content: List[str] = Field(
        default_factory=list,
        description="List of content items for the slide"
    )
    
    slide_type: SlideType = Field(
        default=SlideType.CONTENT,
        description="Type of slide layout"
    )
    
    visual_elements: List[str] = Field(
        default_factory=list,
        description="Suggested visual elements or image placeholders"
    )
    
    notes: Optional[str] = Field(
        None,
        max_length=1000,
        description="Speaker notes for the slide"
    )
    
    slide_number: Optional[int] = Field(
        None,
        ge=1,
        description="Position of slide in the presentation"
    )
    
    @validator('title')
    def validate_title(cls, v):
        """Validate title is not empty after stripping"""
        if not v or not v.strip():
            raise ValueError('Slide title cannot be empty')
        return v.strip()
    
    @validator('content')
    def validate_content(cls, v):
        """Validate and clean content items"""
        if not isinstance(v, list):
            raise ValueError('Content must be a list')
        
        # Clean and filter empty content items
        cleaned_content = []
        for item in v:
            if isinstance(item, str) and item.strip():
                cleaned_content.append(item.strip())
        
        return cleaned_content
    
    @validator('visual_elements')
    def validate_visual_elements(cls, v):
        """Validate and clean visual elements"""
        if not isinstance(v, list):
            raise ValueError('Visual elements must be a list')
        
        # Clean and filter empty visual elements
        cleaned_elements = []
        for item in v:
            if isinstance(item, str) and item.strip():
                cleaned_elements.append(item.strip())
        
        return cleaned_elements
    
    @validator('notes')
    def validate_notes(cls, v):
        """Validate and clean notes if provided"""
        if v is not None:
            v = v.strip()
            if not v:
                return None
        return v
    
    class Config:
        """Pydantic configuration"""
        use_enum_values = True
        json_encoders = {
            SlideType: lambda v: v.value
        }
        json_schema_extra = {
            "example": {
                "title": "What is Machine Learning?",
                "content": [
                    "Machine Learning is a subset of Artificial Intelligence",
                    "Enables computers to learn without explicit programming",
                    "Uses algorithms to find patterns in data"
                ],
                "slide_type": "content",
                "visual_elements": [
                    "ML diagram showing data flow",
                    "Icons representing different ML types"
                ],
                "notes": "Emphasize the practical applications of ML in daily life",
                "slide_number": 2
            }
        }